package cappuccino.couldbook.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.provider.CalendarContract;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;

import cappuccino.couldbook.App;
import cappuccino.couldbook.R;
import cappuccino.couldbook.base.BaseActivity;
import cappuccino.couldbook.core.image.ImageReader;
import cappuccino.couldbook.data.Group;
import cappuccino.couldbook.data.Result;
import cappuccino.couldbook.data.User;
import cappuccino.couldbook.event.ImageReadObserver;
import cappuccino.couldbook.net.Network;
import cappuccino.couldbook.ui.Adapter.RecylerDivider;
import cappuccino.couldbook.ui.Adapter.RecylerGroupAdapter;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/9/10.
 */
public class GroupActivity extends BaseActivity {

    Observer<Result<Group>> observer = new Observer<Result<Group>>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(Result<Group> group) {
            if (show != null) {
                show.setAdapter(new RecylerGroupAdapter(GroupActivity.this,group.data));
                show.setLayoutManager(new LinearLayoutManager(GroupActivity.this));
            }
            if(group.data != null)
                setTitle(group.data.name);
        }
    };


    RecyclerView show;

    int groupId;

    @Override
    protected void bindView() {
        show = (RecyclerView) findViewById(R.id.tv_group_show);
        Intent intent = getIntent();
        if (intent != null) {
            groupId = intent.getIntExtra("groupid", 0);
            Log.v(TAG, "groupid:" + groupId);
            if (groupId != 0)
                Network.getNetApi().groupDetail(groupId).subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(observer);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        showBack();
    }

    @Override
    protected void init() {
        setContentView(R.layout.activity_group);

    }
}
